<?php

declare (strict_types = 1);

namespace app\webadmin\controller;

use app\webadmin\BaseController;
use think\facade\Db;
use think\facade\View;

class Index extends BaseController
{
    public function index()
    {
		$admin = get_login_admin();
		if (get_cache('menu' . $admin['id'])) {
			$list = get_cache('menu' . $admin['id']);
		} else {
			$adminGroup = Db::name('AdminGroupAccess')->where(['uid' => get_login_admin('id')])->column('group_id');
			$adminMenu = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('rules');
			$adminMenus = [];
			foreach ($adminMenu as $k => $v) {
				$v = explode(',', $v);
				$adminMenus = array_merge($adminMenus, $v);
			}
			$menu = Db::name('AdminRule')->where(['menu' => 1,'status'=>1])->where('id', 'in', $adminMenus)->order('sort asc')->select()->toArray();
			$list = list_to_tree($menu);
			\think\facade\Cache::tag('adminMenu')->set('menu' . $admin['id'], $list);
		}
        View::assign('menu', $list);
        return View();
    }

    public function main()
    {
        $adminCount = Db::name('admin')->where('status', '1')->count();
        $wdxCount = Db::name('wendingxing')->count();
        $chongfuCount= Db::name('chongfu')->count();

        $junyunxingCount = Db::name('junyunxing')->count();
        /*$sellsnum = Db::name('sells')->count();*/

        View::assign('adminCount', $adminCount);
        View::assign('wdxCount', $wdxCount);
        View::assign('chongfuCount', $chongfuCount);
        View::assign('junyunxingCount', $junyunxingCount);
        /*View::assign('sellsnum', $sellsnum);*/
		View::assign('TP_VERSION',\think\facade\App::version());
        return View();
    }

}
